package logic

import (
	"context"
	"errors"
	"goods_srv/cache"

	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 购物车列表
func (l *CartListLogic) CartList(in *goods.CartListRequest) (*goods.CartListResponse, error) {
	// todo: add your logic here and delete this line

	cartList, err := cache.CartList(int(in.UserId))
	if err != nil {
		logx.Error("购物车列表展示失败")
		return nil, errors.New("购物车列表展示失败")
	}

	return &goods.CartListResponse{
		List: cartList,
	}, nil
}
